// import vue from '@vitejs/plugin-vue';
import uni from '@dcloudio/vite-plugin-uni';
import vueJsx from '@vitejs/plugin-vue-jsx';
import svgLoader from 'vite-svg-loader';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import Icons from 'unplugin-icons/vite';
import IconsResolver from 'unplugin-icons/resolver';
// import { ElementPlusResolver, VueUseComponentsResolver } from 'unplugin-vue-components/resolvers';
// import WindiCSS from 'vite-plugin-windicss';
// import Markdown from 'vite-plugin-vue-markdown';
// import Prism from 'markdown-it-prism';
// import ViteFonts from 'vite-plugin-fonts';
// import VueI18n from '@intlify/vite-plugin-vue-i18n';
// @ts-ignore
import LinkAttributes from 'markdown-it-link-attributes';
import { ConfigEnv } from 'vite';
// import { resolve } from 'path';

// const defaultClasses = 'prose prose-sm m-auto text-left';

export default (env: ConfigEnv) => {
  return [
    // vue({
    //   include: [/\.vue$/, /\.md$/],
    // }),
      uni(),
    vueJsx(),
    svgLoader(),
    AutoImport({
      dts: './src/auto-imports.d.ts',
      imports: ['vue', 'pinia', 'uni-app', '@vueuse/core', '@vueuse/head'],
      // Generate corresponding .eslintrc-auto-import.json file.
      // eslint globals Docs - https://eslint.org/docs/user-guide/configuring/language-options#specifying-globals
      eslintrc: {
        enabled: false, // Default `false`
        filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
        globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
      },
      // resolvers: [ElementPlusResolver()],
    }),
    Components({
      dts: './src/components.d.ts',
      extensions: ['vue', 'md', 'tsx', 'jsx'],
      include: [/\.vue$/, /\.vue\?vue/, /\.md$/, /\.tsx/, /\.jsx/],
      // imports 指定组件所在位置，默认为 src/components; 有需要也可以加上 view 目录
      dirs: ['src/components/'],
      resolvers: [IconsResolver()],
    }),
    Icons({
      compiler: 'vue3',
      autoInstall: true,
    }),
    // ViteFonts({
    //   google: {
    //     families: ['Open Sans', 'Montserrat', 'Fira Sans'],
    //   },
    // }),
    // VueI18n({
    //   include: [resolve(__dirname, '../locales/**')],
    // }),
    // WindiCSS({
    //   config: {
    //     safelist: defaultClasses,
    //   },
    // }),
    // Markdown({
    //   wrapperClasses: defaultClasses,
    //   headEnabled: false,
    //   markdownItSetup(md) {
    //     // https://prismjs.com/
    //     md.use(Prism);
    //     // 为 md 中的所有链接设置为 新页面跳转
    //     md.use(LinkAttributes, {
    //       matcher: (link: string) => /^https?:\/\//.test(link),
    //       attrs: {
    //         target: '_blank',
    //         rel: 'noopener',
    //       },
    //     });
    //   },
    // }),
  ];
};
